package com.yc.baseapi;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.Date;

public class TestSerializable implements Serializable {
	
	
	
	/**
	 * 
	 */
//	private static final long serialVersionUID = 1L;
	
	private Date loggingDate = new Date();
	private String uid;
	private transient String pwd;
//	private static String aa = "abc";
	private String nn = "nnn";
	
	public TestSerializable(String user, String password) {
		uid = user;
		pwd = password;
	}
	
	public String toString() {
		String password = null;
		if (pwd == null) {
			password = "NOT SET";
		} else {
			password = pwd;
		}
		return "logon info: \n  " + "user: " + uid + "\n loggin date : " + 
			loggingDate.toString() + "\n password: " + password;
	}
	
	public String m2() {
		return "123";
	}

	public static void main(String[] args) {
//		TestSerializable ts = new TestSerializable("Jinder", "Rh-ab703");
//		System.out.println(ts.toString());
//		
//		try {
//			ObjectOutputStream o = new ObjectOutputStream(new FileOutputStream("/Users/yc/yctemp/work-java/logInfo.out"));
//			o.writeObject(ts);
//			o.close();
//			
//		} catch(Exception e) {
//			e.printStackTrace();
//		}
		System.out.println("-----------------------------------");
		try {
			ObjectInputStream in = new ObjectInputStream(new FileInputStream("/Users/yc/yctemp/work-java/logInfo.out"));
			TestSerializable logInfo1 = (TestSerializable)in.readObject();
			System.out.println(logInfo1.toString());
			System.out.println(logInfo1.m2());
//			System.out.println(TestSerializable.aa);
//			System.out.println(logInfo1.nn);
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

}
